package server.fsm;

import java.util.Observable;

public final class ServerContext extends Observable {

	private GenericServerState currentServerState = null;

	public GenericServerState getCurrentServerState() {
		return currentServerState;
	}

	public void setCurrentServerState(GenericServerState currentServerState, String reason) {
		this.currentServerState = currentServerState;
		this.currentServerState.setServerContext( this );
		if( reason != null ) {
			setChanged();
			notifyObservers(reason);
		}
	}

	public ServerContext( GenericServerState serverState ) {
		setCurrentServerState( serverState, null );
	}

	public String login( String username, String password ) {
		return currentServerState.login( username, password );
	}

	public String logout() {
		return currentServerState.logout();
	}

	public String listFiles() {
		return currentServerState.listFiles();
	}

	public String downloadFile( String file, Long size, Long lastModified ) {
		return currentServerState.downloadFile( file, size, lastModified );
	}

	public String uploadFile( String file, Long fileSizeBytes, int chunkSize ) {
		return currentServerState.uploadFile( file, fileSizeBytes, chunkSize );
	}

	public String data( String base64EncodedDataString ) {
		return currentServerState.data( base64EncodedDataString );
	}

	public String waiting( String file, Long size ) {
		return currentServerState.waiting( file, size );
	}

	public String receive( Boolean didFail ) {
		return currentServerState.receive( didFail );
	}

	public String delete( String file ) {
		return currentServerState.delete( file );
	}
	
}
